﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RTUParameterConfig.Class;

namespace RTUParameterConfig.Controls
{
    public partial class CurrentSpeeds : UserControl
    {
        public int intIndex;
        public int DeviceSelectNo;//设备选择序号

        public CurrentSpeeds()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 初始化参数
        /// </summary>
        /// <param name="index">设备标识</param>
        /// <param name="intDeviceSelectNo">设备选择序号</param>
        public void InitValue(int index, int intDeviceSelectNo)
        {
            gc2.Text = Common.CurrentSpeedList1[intDeviceSelectNo].ToString() + (index + 1).ToString();
            DeviceSelectNo = intDeviceSelectNo;
            intIndex = index;
        }

        /// <summary>
        /// 设置流速仪配置
        /// </summary>
        public void SetValue()
        {
            nud11.Value = ParameterConfig.rtuConfigInfo.MultiSpeed_Addr[intIndex];
        }

        /// <summary>
        /// 获置流速仪配置
        /// </summary>
        public void GetValue()
        {
            ParameterConfig.rtuConfigInfo.MultiSpeed_Addr[intIndex] = Convert.ToByte(nud11.Value);
            ParameterConfig.rtuConfigInfo.MultiSpeedDeviceSelect = Convert.ToByte(DeviceSelectNo);
        }

        /// <summary>
        /// 流速仪高级设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOther1_Click(object sender, EventArgs e)
        {
            try
            {
                CurrentSpeedsSetting cs = new CurrentSpeedsSetting(intIndex);
                cs.StartPosition = FormStartPosition.CenterParent;
                cs.ShowDialog();
            }
            catch
            {
                Common.ShowErrorMessage("加载高级设置失败！");
            }
        }
    }
}
